﻿using System;
using LoungeRepo.Contracts.Core;
using LoungeRepo.Contracts.Normalizer;

namespace LoungeRepo.Normalizer
{
    partial class ObjectGraphNormalizer
    {
        private bool TryNormalizeArrayValue(object value, out object normalizedValue)
        {
            if (value != null && value.GetType().IsArray)
            {
                normalizedValue = NormalizeArray((Array)value);
                return true;
            }
            else
            {
                normalizedValue = null;
                return false;
            }
        }

        
        private bool TryNormalizeSimpleTypeValue(object value, out object normalizedValue)
        {
            normalizedValue = value;
            return value == null ||
                   value.GetType().IsPrimitive ||
                   value.GetType().IsEnum ||
                   value is string ||
                   value is decimal ||
                   value is DateTime;
        }


        private object NormalizeComplexTypeValue(object value)
        {
            if (this.normalizedObjectCache.ContainsKey(value))
                return this.normalizedObjectCache[value];

            if (value is ILoungeRepoEntityIdentity)
                return NormalizeEntity(value);
            //TODO: check for entities not implementing ILoungeRepoEntityIdentity

            return NormalizeNonEntity(value);
        }
    }
}
